package com.duowan.realtime.hash;

import java.security.SecureRandom;

public class SecureRandomNumberHashFunction extends AbstractCustomHashFunction{
	@Override
	public int[] hash(byte[] value, int m, int k) {
		setK(k);
		setM(m);
		return hashSecureRNG(value);
	}
	
	/**
	 * Secure Java 随机数发生器 
	 * @param value the value to be hashed
	 * @return array with <i>k</i> integer hash positions in the range <i>[0,m)</i>
	 */
	protected int[] hashSecureRNG(byte[] value) {
		int[] positions = new int[k];
		SecureRandom r = new SecureRandom(value);
		for (int i = 0; i < k; i++) {
			positions[i] = r.nextInt(m);
		}
		return positions;
	}

}
